package com.hd123.rumba.catalog;

import com.hd123.rumba.exception.StringTooLongException;
import com.hd123.rumba.runtime.BaseEntity;

/**
 * @author caili
 */
public class Category extends BaseEntity implements ICategory {
  private ICatalog catalog;
  private String code;
  private String name;
  private String usedType;
  private ICategory parent;
  private String remark;

  public static final int LENGTH_CODE = 16;
  public static final int LENGTH_NAME = 50;
  public static final int LENGTH_USEDTYPE = 50;
  public static final int LENGTH_REMARK = 255;

  public ICatalog getCatalog() {
    return catalog;
  }

  public void setCatalog(ICatalog catalog) {
    this.catalog = catalog;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) throws StringTooLongException {
    if (code != null) {
      code = code.trim().toUpperCase();
      code = truncate(code, LENGTH_CODE, "code", CAPTION_CODE);
    }
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) throws StringTooLongException {
    if (name != null) {
      name = name.trim().toUpperCase();
      name = truncate(name, LENGTH_NAME, "name", CAPTION_NAME);
    }
    this.name = name;
  }

  public ICategory getParent() {
    return parent;
  }

  public void setParent(ICategory parent) {
    this.parent = parent;
  }

  public String getUsedType() {
    return usedType;
  }

  public void setUsedType(String usedType) throws StringTooLongException {
    if (usedType != null) {
      usedType = usedType.trim().toUpperCase();
      usedType = truncate(usedType, LENGTH_USEDTYPE, "usedType", CAPTION_USEDTYPE);
    }
    this.usedType = usedType;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) throws StringTooLongException {
    if (remark != null) {
      remark= remark.trim().toUpperCase();
      remark= truncate(remark, LENGTH_REMARK, "remark", CAPTION_REMARK);
    }
    this.remark = remark;
  }
  
  public String toString() {
    return getCode() + "-" + getName();
  }
  
  public String getCodeName() {
    return getCode().concat("[").concat(getName()).concat("]");
  }

  public String getNameCode() {
    return getName().concat("[").concat(getCode()).concat("]");
  }
}
